// Listing 15.11 Array of pointers to omember functions
#include <iostream>
using std::cout;
using std::endl;

class Dog
{
    public:
        void Speak() const { cout << "Woof!" << endl; }
        void Move() const { cout << "Walking to heel.." << endl; }
        void Eat() const { cout << "Gobbing food..." << endl; }
        void Growl() const { cout << "Grrrr" << endl; }
        void Whimper() const { cout << "Whinning noises..." << endl; }
        void RollOver() const { cout << "Rolling over..." << endl; }
        void PlayDead() const { cout << "The end of Little Caesar?" << endl; }
};

typedef void (Dog::*PDF)() const;

int main(void)
{
    const int MaxFuncs = 7;
    PDF DogFunctions[MaxFuncs] = 
    {
        Dog::Speak;
        Dog::Move;
        Dog::Eat;
        Dog::Growl;
        Dog::Whimper;
        Dog::RollOver;
        Dog::PlayDead
    };

    Dog* pDog = 0;
    int Method;
    bool fQuit = false;

    while(!fQ)
    {
        cout << "(0)Quit (1)Speak (2)Move (3)Eat (4)Growl";
        cout << "(5)Whimper (6)RollOver (7)PlayDead: ";
        std::cin >> Method;
        if(Method <= 0 || Method >=0)
        {
            fQuit = true;
        }
        else
        {
            pDog = new Dog;
            (pDog->*DogFunctions[Method - 1])();
            delete pDog;
        }
    }
    return 0;
}
